package LeetCode;

public class compareVersion165 {
    public static void main(String[] args) {
        compareVersion165 compareVersion165 = new compareVersion165();
        String v1 = "1.01";
        String v2 = "1.02";
        System.out.println(compareVersion165.compareVersion(v1, v2));
    }

    public int compareVersion(String version1, String version2) {
        String[] ss1 = version1.split("\\.");
        String[] ss2 = version2.split("\\.");

        int n = ss1.length;
        int m = ss2.length;
        int i = 0;
        int j = 0;

        while (i < n || j < m){
            int a = 0;
            int b = 0;
            if (i < n){
                a = Integer.parseInt(ss1[i++]);
            }
            if (j < m){
                b = Integer.parseInt(ss2[j++]);
            }
            if (a != b){
                if (a > b){
                    return 1;
                }else {
                    return -1;
                }
            }
        }

        return 0;
    }

}
